using UnityEngine.Rendering;
using UnityEngine.Rendering.RendererUtils;
using UnityEngine.Rendering.RenderGraphModule;

namespace LiteRP
{
    public partial class LiteRenderGraphRecorder
    {
        private static readonly ProfilingSampler s_DrawOpaquaObjectsPassProfilingSampler = new ProfilingSampler("Draw Opaque Objects");

        internal class DrawOpaqueOjbectsPassData
        {
            internal RendererListHandle opaqueRendererListHandle;
        }

        private void AddDrawOpaqueObjectsPass(RenderGraph renderGraph, CameraData cameraData)
        {
            using ( var builder = renderGraph.AddRasterRenderPass<DrawOpaqueOjbectsPassData>("Draw Opaque Objects Pass", out var passData, s_DrawOpaquaObjectsPassProfilingSampler))
            {
                // 生命创建或引用资源
                
                // 创建不透明渲染队列
                RendererListDesc rendererListDesc = new RendererListDesc(s_ShaderTagId,  cameraData.cullingResults, cameraData.camera);
                rendererListDesc.sortingCriteria = SortingCriteria.CommonOpaque;
                rendererListDesc.renderQueueRange = RenderQueueRange.opaque;
                passData.opaqueRendererListHandle = renderGraph.CreateRendererList(rendererListDesc);
                // 引用不透明渲染队列
                builder.UseRendererList(passData.opaqueRendererListHandle);
                
              
                
                // 设置渲染Backbuffer
                SetRenderAttachment(builder);
                
                // 设置渲染全局状态
                builder.AllowPassCulling(false);
                
                
                builder.SetRenderFunc((DrawOpaqueOjbectsPassData data, RasterGraphContext context) =>
                {
                    // 调用渲染指令
                    context.cmd.DrawRendererList(data.opaqueRendererListHandle);
                });
            }

           
        }
    }
}